package main

import "go-leetcode/leetcode/utils"

func main() {
	head := utils.GetListNodeByArray([]int{1, 2, 3, 4, 5})

	newHead := reverseList(head)

	point := newHead

	for point != nil {
		print(point.Val, "->")
		point = point.Next
	}
}

func reverseList(head *utils.ListNode) *utils.ListNode {
	var newHead *utils.ListNode

	for head != nil {
		nextNode := head.Next

		head.Next = newHead
		newHead = head

		head = nextNode
	}

	return newHead
}
